package com.tuojiahr.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.tuojiahr.domain.TuoJiaHrQQContact;
import com.tuojiahr.service.QQService;

/**
 * 说明：
 *
 * @author wang.haibo
 * @date 2012-11-12 上午1:03:19
 */

@Transactional
public class QQServiceImpl extends HibernateDaoSupport implements QQService {

	//添加
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void addQq(TuoJiaHrQQContact qq) {
		Date now = new Date();
		qq.setCreateTime(now);
		qq.setUpdateTime(now);
		getHibernateTemplate().persist(qq);
	}

	//更新
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void updateQq(TuoJiaHrQQContact qq) {
		qq.setUpdateTime(new Date());
		getHibernateTemplate().update(qq);
	}

	//删除，支持批量
	@Override
	@Transactional(propagation=Propagation.REQUIRED)
	public void deleteQq(String ids) {
		String[] idArr = ids.split("\\|");
		for (String id : idArr) {
			getHibernateTemplate().delete(getQqById(Long.valueOf(id)));
		}
	}

	//根据Id查询
	@Override
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public TuoJiaHrQQContact getQqById(long id) {
		return getHibernateTemplate().load(TuoJiaHrQQContact.class, id);
	}

	//获得列表
	@SuppressWarnings("unchecked")
	@Override
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<TuoJiaHrQQContact> getQqList() {
		return getSession().createQuery("from TuoJiaHrQQContact qq").list();
	}

}
